home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / java / applets / graphs / lineap~1.jav < prev    next >
Encoding:
Text File  |  1995-10-31  |  4.8 KB  |  147 lines

  1. /* 
  2.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  6.  * without fee is hereby granted.
  7.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  8.  * for further important copyright and trademark information and to
  9.  * http://java.sun.com/licensing.html for further important licensing
  10.  * information for the Java (tm) Technology.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  20.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  21.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  22.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  23.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  24.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  25.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  26.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  27.  * HIGH RISK ACTIVITIES.
  28.  */
  29. import java.lang.*;
  30. import java.io.*;
  31. import java.awt.*;
  32. import java.applet.*;
  33. import java.util.*;
  34. import Display;
  35. import java.net.*; 
  36. /**
  37.  * 
  38.  *
  39.  * @author      Siebe R. Brouwer
  40.  * version      1.1, 13 october 1995
  41.  */
  42.  
  43. public class LineApplet extends Applet {
  44.  
  45.     protected Display display;
  46.     protected LineDiagram diagram;
  47.     
  48.     public void init() {
  49.     String at = getParameter("filename");
  50.     String fileName = (at != null) ? at : "lines.data";
  51.     at = getParameter("dir");
  52.     String dir = (at != null) ? at : "dataFiles/";
  53.     at = getParameter("header");
  54.     String header = (at != null) ? at : "BAR DIAGRAM";
  55.     at = getParameter("xtext");
  56.     String xText = (at != null) ? at : "x-axis";
  57.     at = getParameter("ytext");
  58.     String yText = (at != null) ? at : "y-axis";
  59.     at = getParameter("vxbegin");
  60.     int vXbegin = (at != null) ? Integer.valueOf(at).intValue() :0;
  61.     at = getParameter("vxgap");
  62.     int vXgap = (at != null) ? Integer.valueOf(at).intValue() :100;
  63.     at = getParameter("vybegin");
  64.     int vYbegin = (at != null) ? Integer.valueOf(at).intValue() :0;
  65.     at = getParameter("vygap");
  66.     int vYgap = (at != null) ? Integer.valueOf(at).intValue() : 100;
  67.     at = getParameter("xgap");
  68.     int xGap = (at != null) ? Integer.valueOf(at).intValue() : 50;
  69.     at = getParameter("ygap");
  70.         int yGap = (at != null) ? Integer.valueOf(at).intValue() : 50;
  71.         setLayout(new BorderLayout());
  72.     display = new Display(header,xText, yText, xGap, yGap);
  73.     add("Center",display);    
  74.     
  75.         // create a new LineDiagram
  76.     diagram = new LineDiagram(vXbegin, vYbegin, vXgap, vYgap, display);
  77.             
  78.     
  79.     runDiagram(fileName, dir);
  80.     }
  81.  
  82.     public void runDiagram(String fileName, String dir) {
  83.     
  84.         URL url = new URL(getDocumentBase(), dir + fileName);
  85.     DataInputStream file = new DataInputStream(url.openStream());
  86.         
  87.     String number;
  88.     String line;
  89.     number = nextLine(file);
  90.     int nrOfLines = Integer.valueOf(number).intValue();
  91.     int c[] = new int[3];
  92.     String d[] = new String[3];
  93.     StringTokenizer t;
  94.     for(int i = 0; i < nrOfLines; i++) {
  95.         String index;
  96.         index=nextLine(file);
  97.         
  98.         line = nextLine(file);
  99.         t= new StringTokenizer(line,",");
  100.         String n=null;
  101.         int j = 0;
  102.         while(t.hasMoreTokens()) {
  103.             n = t.nextToken().trim();
  104.         c[j] = Integer.valueOf(n).intValue();    
  105.         j++;
  106.         }
  107.             number=nextLine(file);
  108.         int nrOfDots = Integer.valueOf(number.trim()).intValue();
  109.             Color color = new Color(c[0], c[1], c[2]);
  110.             diagram.createLine(color, index);
  111.             for(int k = 0; k < nrOfDots; k++) {
  112.             line=nextLine(file);
  113.             t = new StringTokenizer(line,",");
  114.             j = 0;
  115.             while(t.hasMoreTokens()) {
  116.             d[j] = t.nextToken().trim();     
  117.                 j++;
  118.             }
  119.             int x = Integer.valueOf(d[1]).intValue();
  120.             int y = Integer.valueOf(d[2]).intValue();
  121.             for(int l = 0; l < 3;l++) {
  122.             diagram.addDot(x, y, d[0], index);
  123.             }
  124.         }
  125.     }
  126.         display.drawDiagram(diagram);
  127.     }
  128.     
  129.     /* is the String "line" empty or begins with an "#" 
  130.      * then return true, else return false.
  131.      */
  132.     protected String nextLine(DataInputStream file) {
  133.     String line = file.readLine().trim();
  134.     while(line.startsWith("#") || line.length() == 0) {
  135.         line = file.readLine().trim();
  136.     }
  137.     return line;
  138.     }    
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.